package Core;

import com.lmax.disruptor.EventTranslatorOneArg;
import com.lmax.disruptor.RingBuffer;

import java.nio.ByteBuffer;

public class ByteArrayEventProducer {
    private final RingBuffer<ByteArrayEvent> ringBuffer;

    public ByteArrayEventProducer(RingBuffer<ByteArrayEvent> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    private static final EventTranslatorOneArg<ByteArrayEvent, byte[]> TRANSLATOR =
            new EventTranslatorOneArg<ByteArrayEvent, byte[]>()
            {
                public void translateTo(ByteArrayEvent event, long sequence, byte[] ba)
                {
                    event.set(ba);
                }
            };

    public void onData(byte[] ba)
    {
        System.out.println("onData Thread: " + Thread.currentThread().getId());
        ringBuffer.publishEvent(TRANSLATOR, ba);
    }
}
